package com.tuananh.radnom.service.discovery.impl;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import org.dhcp4java.DHCPPacket;

import com.tuananh.radnom.model.NetInterface;
import com.tuananh.radnom.model.NetNode;
import com.tuananh.radnom.model.discovery.DiscoverNetInt;
import com.tuananh.radnom.model.protocol.service.PassiveDiscover;
import com.tuananh.radnom.service.config.impl.DiscoverService;
import com.tuananh.radnom.service.config.impl.NetIntService;
import com.tuananh.radnom.service.config.impl.NetNodeService;
import com.tuananh.radnom.service.discovery.AbstractDiscoverd;

public class PassiveDiscoverd extends AbstractDiscoverd {

	public void run() {
		// TODO Auto-generated method stub
		System.out.println("" + getDiscoverService().isPassiveDiscover());
		if (getDiscoverService().isPassiveDiscover()) {
			setStop(false);
			ArrayList<PassiveDiscover> list = getDiscoverService()
					.getAllPassiveDiscover();
			ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(
					20);
			for (PassiveDiscover discoverer : list) {
				if (discoverer.isEnable()) {
					discoverer.addObserver(this);
					pool.submit(discoverer);
				}
			}
			while (!isStop()) {
				try {
					Thread.sleep(100);
				} catch (Exception e) {
					e.printStackTrace();
				}

			}
			pool.shutdown();
		}
	}

}
